package com.sunchangming.uniqname;

import static org.junit.Assert.fail;
import junit.framework.Assert;

import org.apache.log4j.BasicConfigurator;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class ServiceImplTest {
	private static UniqClient uc;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		BasicConfigurator.configure();
		uc = new UniqClient("localhost", 10000);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		uc.shutdown();
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAllocateWithoutRegister() throws Exception {
		Assert.assertTrue("清空数据库", uc.clearAll());
		Assert.assertFalse("测试分配", uc.allocate("role", "scm"));
	}

	@Test
	public void testAllocate() throws Exception {
		Assert.assertTrue("清空数据库", uc.clearAll());
		Assert.assertTrue("测试分配", uc.register(1));
		Assert.assertTrue("测试分配", uc.allocate("role", "scm"));
	}

	@Test
	public void testConfirm() {
		Assert.assertTrue("清空数据库", uc.clearAll());
		Assert.assertFalse("测试分配", uc.allocate("role", "scm"));
		Assert.assertFalse("测试确认", uc.confirm("role", "scm"));
	}

	@Test
	public void testRelease() {
		fail("Not yet implemented");
	}

	@Test
	public void testExist() {
		fail("Not yet implemented");
	}

}
